package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.example.yuejianapp14.Activity.Adapter.UserEnteredAdapter;
import com.example.yuejianapp14.Activity.JavaBean.Enter;
import com.example.yuejianapp14.Activity.Listener.EnterListener;
import com.example.yuejianapp14.Activity.Model.EnterModel;
import com.example.yuejianapp14.R;

import java.util.List;

public class UserEnterActivity extends AppCompatActivity {
    private SharedPreferences sp;
    private RecyclerView recyclerView;
    private Context mContext;
    private ImageView back;
    private Button user_enter,user_entered;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_enter);
        sp=getSharedPreferences("uid",MODE_PRIVATE);
        Intent intent=getIntent();
//        User_NoEnteredlist();
       User_Enteredlist();
        initViews();
        initEvent();

    }
    public void initViews() {
        recyclerView = (RecyclerView)findViewById(R.id.rv_user_enter);
        recyclerView.setLayoutManager(new LinearLayoutManager((mContext)));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        sp=getSharedPreferences("uid",MODE_PRIVATE);
        back = (ImageView) findViewById(R.id.back);
    }
    public void initEvent(){
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
//        user_enter.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                User_NoEnteredlist();
//
//            }
//        });
//        user_entered.setOnClickListener(new View.OnClickListener() {
//          @Override
//           public void onClick(View v) {
//              User_Enteredlist();
//            }
//        });
    }
    public void User_Enteredlist(){
        EnterModel enterModel =new EnterModel();
        enterModel.getEnteredList(sp.getString("uid",""), EnteredListListener);
    }
//    public  void User_NoEnteredlist(){
//        EnterModel enterModel =new EnterModel();
//        enterModel.getEnteredList(sp.getString("uid",""), NoEnteredListListener);
//    }
    EnterListener EnteredListListener = new EnterListener() {
        @Override
        public void onResponse(List<Enter> beanList) {

            recyclerView.setAdapter(new UserEnteredAdapter(UserEnterActivity.this,beanList));
        }

        @Override
        public void onFail(String msg) {

        }
    };
//    EnterListener NoEnteredListListener = new EnterListener() {
//        @Override
//        public void onResponse(List<Enter> beanList) {
//
//            recyclerView.setAdapter(new UserEnteredAdapter(UserEnterActivity.this,beanList));
//        }
//
//        @Override
//        public void onFail(String msg) {
//
//        }
//    };

}
